﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CNVP.JShop.Web.Admin.CommonWindows
{
    public partial class AjaxRefShopMustInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string result = Request.QueryString["result"];
            string SaleNum = Request.QueryString["SaleNum"];
            if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(SaleNum))
            {
                string _ProDetailNo = "";
                decimal _SalePrice = 0;
                

                string AddTr = "";
                string[] resultArray = result.Split(Convert.ToChar(","));
                for (int i = 0; i < resultArray.Length; i++)
                {
                    string _StandardValueName = "";
                    string[] SaleNumArray = SaleNum.Split(Convert.ToChar(","));//销售数量
                    string[] IDSArray = resultArray[i].Split(Convert.ToChar("_"));
                    BLL.CNVP_Products bll_Products = new BLL.CNVP_Products();
                    BLL.CNVP_ProductsDetail bll_ProductsDetail = new BLL.CNVP_ProductsDetail();
                    var Product_model = bll_Products.GetSingle_CNVP_ProductsById(Convert.ToInt32(IDSArray[0]));
                    if (IDSArray[1] != "0")
                    {
                        var ProductDetail_model = bll_ProductsDetail.GetSingle_CNVP_ProductsDetailById(Convert.ToInt32(IDSArray[1]));
                        if (ProductDetail_model != null)
                        {
                            _ProDetailNo = ProductDetail_model.ProDetailNo;

                            string StandardValueName = "（";
                            string[] StandardValueIDsArray = ProductDetail_model.StandardValueIDs.Split(Convert.ToChar(","));
                            for (int k = 0; k < StandardValueIDsArray.Length; k++)
                            {
                                var model_StandardValue = new BLL.CNVP_StandardValue().GetSingle_CNVP_StandardValueById(int.Parse(StandardValueIDsArray[k]));
                                if (model_StandardValue != null)
                                {
                                    StandardValueName += model_StandardValue.StandardValueName + "、";
                                }
                            }
                            if (!string.IsNullOrEmpty(StandardValueName))
                            {
                                StandardValueName = StandardValueName.Substring(0, StandardValueName.Length - 1) + "）";
                            }
                            _StandardValueName = StandardValueName;

                            _SalePrice = ProductDetail_model.SalePrice;
                        }
                    }
                    else
                    {
                        if (Product_model != null)
                        {
                            _ProDetailNo = Product_model.ProductNo;
                            _SalePrice = Product_model.TradePrice;
                        }
                    }
                    if (Product_model != null)
                    {
                        var model_ProductType = new BLL.CNVP_ProductType().GetSingle_CNVP_ProductTypeById(Product_model.ProductTypeID);
                        if(model_ProductType!=null)
                        {
                            byte IsRefShopMustInfo = model_ProductType.IsRefShopMustInfo;
                            if (IsRefShopMustInfo == 1)
                            {
                                string _ValueName= _StandardValueName + "<font color=\"red\"> x " + SaleNumArray[i] + "</font>";
                                AddTr += "<h3>填写购买 " + Product_model.ProductName + "-" + _ProDetailNo + "-" + _ValueName + " 时所需信息";
                                AddTr += "<input type=\"hidden\" id=\"ProID_ProDetailIDS" + resultArray[i] + "\" name=\"ProID_ProDetailIDS\" value=\"" + resultArray[i] + "\" /></h3>";
                                var ProTypeRefShopMustInfo_List = new BLL.CNVP_ProTypeRefShopMustInfo().GetAll_CNVP_ProTypeRefShopMustInfo(Convert.ToInt32(Product_model.ProductTypeID));
                                AddTr += "<table id=\"tableEdit\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"division\">";
                                if (ProTypeRefShopMustInfo_List != null && ProTypeRefShopMustInfo_List.Count > 0)
                                {
                                    for (int j = 0; j < ProTypeRefShopMustInfo_List.Count; j++)
                                    {
                                        string html = "";
                                        if (ProTypeRefShopMustInfo_List[j].ShowWay == 0)
                                        {
                                            html += "<tr>";
                                            html += "   <th>";
                                            html += "   " + ProTypeRefShopMustInfo_List[j].MustInfoName + "";
                                            html += "       <input id=\"CKRefShopMustInfo" + resultArray[i] + "\" name=\"CKRefShopMustInfo" + resultArray[i] + "\" type=\"checkbox\" checked=\"checked\" value=\"" + ProTypeRefShopMustInfo_List[j].ID + "\" class=\"Display\" />";
                                            html += "   </th>";
                                            html += "   <td>";
                                            html += "   <input type=\"text\" id=\"MustInfoValue" + resultArray[i] + "\" name=\"MustInfoValue" + resultArray[i] + "\" /></td>";
                                            html += "</tr>";
                                        }
                                        else if (ProTypeRefShopMustInfo_List[j].ShowWay == 1)
                                        {
                                            html += "<tr>";
                                            html += "   <th>";
                                            html += "   " + ProTypeRefShopMustInfo_List[j].MustInfoName + "";
                                            html += "       <input id=\"CKRefShopMustInfo" + resultArray[i] + "\" name=\"CKRefShopMustInfo" + resultArray[i] + "\" type=\"checkbox\" checked=\"checked\" value=\"" + ProTypeRefShopMustInfo_List[j].ID + "\" class=\"Display\" />";
                                            html += "   </th>";
                                            html += "   <td>";
                                            html += "   <textarea id=\"MustInfoValue" + resultArray[i] + "\" cols=\"20\"  name=\"MustInfoValue" + resultArray[i] + "\" rows=\"5\" style=\"width:455px;\"></textarea></td>";
                                            html += "</tr>";
                                        }
                                        else if (ProTypeRefShopMustInfo_List[j].ShowWay == 2)
                                        {
                                            html += "<tr>";
                                            html += "   <th>";
                                            html += "   " + ProTypeRefShopMustInfo_List[j].MustInfoName + "";
                                            html += "       <input id=\"CKRefShopMustInfo" + resultArray[i] + "\" name=\"CKRefShopMustInfo" + resultArray[i] + "\" type=\"checkbox\" checked=\"checked\" value=\"" + ProTypeRefShopMustInfo_List[j].ID + "\" class=\"Display\" />";
                                            html += "   </th>";
                                            html += "   <td>";
                                            html += "   <select id=\"MustInfoValue" + resultArray[i] + "\" name=\"MustInfoValue" + resultArray[i] + "\">";
                                            html += "	<option value=\"0\">--请选择--</option>";
                                            string _MustInfoValue=ProTypeRefShopMustInfo_List[j].MustInfoValue;
                                            if (!string.IsNullOrEmpty(_MustInfoValue))
                                            {
                                                string[] MustInfoValueArray = _MustInfoValue.Split(Convert.ToChar("|"));
                                                for (int k = 0; k < MustInfoValueArray.Length; k++)
                                                {
                                                    if (MustInfoValueArray[k] != "")
                                                    {
                                                        html += "       <option value=\"" + MustInfoValueArray[k] + "\">" + MustInfoValueArray[k] + "</option>";
                                                    }
                                                }
                                            }
                                            html += "   </select>";
                                            html += "   </td>";
                                            html += "</tr>";
                                        }
                                        AddTr += html;
                                    }
                                }
                                AddTr += "</table>";
                            }
                        }
                    }
                }
                Response.Write(AddTr);
            }
        }
    }
}